<?php
include_once("../inc/global.php");
include_once './menu_fun.php';

if( $_POST['ispost'] ){
	$n = $_POST['n'];
	$sql = "SELECT MAX(sort) FROM menu WHERE pid = {$n['pid']}";
	$sort = $db->getOne( $sql );
	
	$n['sort'] = $sort + 1;
	$ret = $db->insert( 'menu', $n );
	if( $ret ){
		$str = '新增成功！';
		
		write_menu_cache();	
		
	}else{
		$str = '新增失败！';	
	}
	echo'<script type="text/javascript">
		alert("'.$str.'");
		parent.art.dialog({id:"a"}).close();
		document.getElementById("rightMain").contentWindow.document.location.reload();
	</script>';	
}

//note 取得所有显示位置，即一级菜单
$sql = "SELECT * FROM menu WHERE pid = 0 ORDER BY sort ASC";
$menu = $db->getAll( $sql );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CMS</title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="./frame/js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="./frame/css/table_form.css" />
</head>
<body>
  <form method="post" id="myform" onSubmit="return check();">
        <table width="100%" class="table_form">
        <tr>
          <td width="80">上级菜单位置</td>
          <td><select name="n[pid]" id="pid">
          	<option value="0">--根菜单--</option>
           <?php foreach( $menu as $v){?>
            <option value="<?php echo $v['mid'];?>"><?php echo $v['name'];?></option>
            <?php }?>
            </select></td>
        </tr>
        <tr>
          <td>菜单名称</td>
          <td><input type="text" name="n[name]" id="name" class="input-text" size="30" value=""/></td>
        </tr>
      <tr id="a_b_c" style="display:none;">
        <td valign="top">&nbsp;</td><td>&nbsp;</td></tr>
      </table>
      <input name="dosubmit" type="submit" value=" 提 交 " class="button" id="dosubmit" />
    <input type="hidden" name="ispost" value="1" />
    </form>
<script type="text/javascript">
function check(){
	var name = $("#name").val();
	if( !name ){
		alert("模块名称不能为空！");
		return false;	
	}	
	return true;
}
</script>
</body>
</html>


